//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Files.Components;

namespace CommunityServer.Files.Controls
{
	/// <summary>
	/// Summary description for TagCloud.
	/// </summary>
	public class TagCloud : CommunityServer.Controls.BaseTagCloud
	{
		protected override ArrayList Tags
		{
			get
			{
				if (tags == null)
				{
					if (this.FilterTags != null)
						tags = CommunityServer.Components.Tags.GetTagsBySection(this.Folder.SectionID, this.FilterTags);
					else
						tags = CommunityServer.Components.Tags.GetTagsBySection(this.Folder.SectionID);
				}

				return tags;
			}
		}

		protected override string GetTagUrl(string tagName)
		{
			if (this.FilterTags == null)
				return FileGalleryUrls.Instance().TagsBrowser(this.Folder.ApplicationKey, new String[] {tagName});
			else
			{
				ArrayList linkTags = new ArrayList(this.FilterTags);
				linkTags.Add(tagName);
				return FileGalleryUrls.Instance().TagsBrowser(this.Folder.ApplicationKey, (string[]) linkTags.ToArray(typeof(string)));
			}
		}

		private Folder folder = null;
		public virtual Folder Folder
		{
			get
			{
				if (folder == null)
				{
					folder = Folders.GetFolder(csContext.ApplicationKey);
					Permissions.AccessCheck(folder,Permission.View,csContext.User);
				}

				return folder;
			}
		}
	}
}
